#!/usr/bin/python2.5
# -*- coding: us-ascii -*-
# vim:ts=4:sw=4:softtabstop=4:smarttab:expandtab


"""
Selenium wrapper tests
----------------------

Test cases for the Pycopia selenium wrapper.

"""

from pycopia.QA import core
from pycopia.QA import selenium

__author__ = "keith@dartworks.biz"


class PycopiaTest(core.Test):
    """
    Purpose
    +++++++

    Verify the selenium by loading the Pycopia webiste page.

    Pass Criteria
    +++++++++++++

    Pycopia home page is loaded and detected.

    Start Condition
    +++++++++++++++

    None.

    End Condition
    +++++++++++++

    No change.

    Reference
    +++++++++

    None

    Prerequistes
    ++++++++++++

    None

    Procedure
    +++++++++

    - Load the main page of the environment's DUT.
    - Wait up to 30 seconds for the page to load.
    - Verify "Pycopia Application Framework" is found.

    """

    def execute(self):
        checkfor = self.config.get("checkfor", "Python Application Frameworks")
        sel = self.config.selenium
        sel.open("/")
        sel.wait_for_page_to_load("30000")
        self.failUnless(sel.is_text_present(checkfor), "Not present: {!r}".format(checkfor))
        return self.passed("Got page with desired text present.")


class PycopiaQATest(core.Test):
    """
    Purpose
    +++++++

    Verify Pycopia webUI test management page loads.

    Pass Criteria
    +++++++++++++

    Pycopia test management (qa) page loads.

    Start Condition
    +++++++++++++++

    None.

    End Condition
    +++++++++++++

    No change.

    Reference
    +++++++++

    None

    Prerequiste
    +++++++++++

    PycopiaTest

    Procedure
    +++++++++

    - Load the /qa locatation of the environment DUT.
    - Wait up to 30 seconds for the page to load.
    - Verify "Test Management" is found.

    """
    PREREQUISITES = ["PycopiaTest"]

    def execute(self):
        sel = self.config.selenium
        sel.open("/qa")
        sel.wait_for_page_to_load("30000")
        self.failUnless(sel.is_text_present("Test Management"))
        return self.passed("Got QA test management page.")

def get_suite(config):
    suite = selenium.SeleniumSuite(config, name="SeleniumUnitTestSuite")
    suite.add_test(PycopiaTest)
    suite.add_test(PycopiaQATest)
    return suite


def run(config):
    suite = get_suite(config)
    suite.run()

